# -*- coding: utf-8 -*-
"""
@Time ： 2023/10/4 0004 9:03
@Auth ： zpt
@File ：custom_image_page.py
@IDE ：PyCharm
"""
import time
from Page.base_page import BasePage
from Page.image_build_page import ImageBuildPage
from Page.login_page import LoginPage
from Lib.readelement import Element
from Lib.log import log

image_package = Element('custom_packages')


class CustomPackagesPage(BasePage):
    """镜像定制页面"""
    product_name = "openEuler"
    config_kernel = "net.ifnames=0 biosdevname=0 crashkernel=512M"
    repo_url = 'https://repo.openeuler.org/openEuler-22.03-LTS/everything/x86_64/'
    config_version = "1.1"

    def login(self, url=None, name=None, password=None):
        """
        用户登录
        """
        login = LoginPage(self.driver)
        login.login(url, name, password)

    def click_custom_packages(self):
        """
        点击定制业务包按钮
        """
        try:
            self.click(image_package["custom_packages_btn"])
        except Exception as e:
            log.error("error: found custom packages button timeout")
            log.info(e)

    def click_edit_btn(self):
        """
        点击定制业务包页面修改按钮
        """
        try:
            self.click(image_package["edit_btn"])
        except Exception as e:
            log.error("error: found edit button timeout")
            log.info(e)

    def click_save_btn(self):
        """
         点击定制业务包页面保存按钮
         """
        try:
            self.click(image_package["save_btn"])
        except Exception as e:
            log.error("error: found save button timeout")
            log.info(e)

    def custom_packages_info(self, product_name, config_kernel, repo_url):
        """
        定制业务包页面产品名称、配置内核参数、添加repo源 输入框内容输入
        """
        self.click_custom_packages()
        time.sleep(3)
        self.click_edit_btn()
        time.sleep(3)
        self.send_keys(image_package["name"],product_name)
        self.send_keys(image_package["kernel"], config_kernel)
        self.send_keys(image_package["url"], repo_url)
        time.sleep(2)
        self.driver.execute_script('window.scrollTo({top: 0});')
        self.click_save_btn()